<template>
	<view class="card-page">
		<view class="padd-top40">
			<view class="flex flex-direction align-center">
				<image :src="`https://www.worldintek.com:39011/yaolexue-service/${userInfo.icon}`" class="avatar">
				</image>
				<view class="cr-fff font_s42 font_w500 text_center mar-top32">
					{{userInfo.name}}
				</view>
				<view class="card-box flex flex-direction align-center mar-top73">
					<view class="card-title">
						二维码名片
					</view>
					<view class="flex flex-direction align-center">
						<image :src="qrCode" class="qrcodeimg"></image>
						<view class="tips font_s28 font_w500 mar-top8">
							扫一扫加入药乐学
						</view>
					</view>
					<view @click="clickSave" class="btn flex align-center justify-center mar-top138">
						保存图片到本地
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="share-btn">
			分 享
		</view> -->
	</view>
</template>

<script>
	const app = getApp().globalData
	export default {
		data() {
			return {
				userInfo: app.userInfo,
				qrCode:''
			};
		},
		onLoad() {
			console.log(this.userInfo)
			this.getQRCode()
		},
		methods:{
			getQRCode(){
				this.$http.get(`/yaolexue-service-portal/sysPortalUser/portalUserShareCode`,{
					
				}).then(res => {
					if(res.code == 200){
						this.qrCode =  `data:image/png;base64,${res.data}`
					}
				})
			},
			clickSave(){
				this.$scopeAlbum().then(() => {
					uni.showLoading({
						title:'保存中'
					})
					this.$base64ImgToFilePath(this.qrCode).then(tempFilePath => {
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success: () => {
								console.log('保存成功')
								uni.showToast({
									title:'保存成功'
								})
							},
							fail: (e) => {
								console.error(e,'===>保存失败')
								uni.showToast({
									title:'保存失败',
									icon:'error'
								})
							},
							complete() {
								uni.hideLoading()
							}
						});
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card-page {
		width: 100%;
		min-height: 100vh;
		overflow: hidden;
		background: #FA312A;
		padding-bottom: 40rpx;

		.avatar {
			width: 199rpx;
			height: 199rpx;
			border-radius: 50%;
		}
	}

	.card-box {
		width: 639rpx;
		height: 880rpx;
		// background: #FFFFFF;
		background-image: url(/static/img/qrcodebg.png);
		background-size: 100% 100%;
		box-shadow: 0px 5rpx 15rpx 0px rgba(0, 0, 0, 0.1);

		.card-title {
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #FA312A;
			padding-top: 72rpx;
		}

		.qrcodeimg {
			width: 412rpx;
			height: 413rpx;
			margin-top: 16rpx;
		}

		.tips {
			color: #8D8D8D;
		}

		.btn {
			width: 480rpx;
			height: 96rpx;
			background: #6A1512;
			border-radius: 48rpx;
			font-size: 32rpx;
			font-family: Adobe Heiti Std;
			font-weight: normal;
			color: #FFFFFF;
		}
	}

	.share-btn {
		width: 480rpx;
		height: 96rpx;
		border: 2rpx solid #FFFFFF;
		border-radius: 48rpx;
		font-size: 32rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 73rpx auto 10rpx auto;
	}
</style>